package org.gpf;

import java.util.Arrays;
/**
 * 冰雹序列
 * @author gaopengfei
 * @date 2015-4-22 下午6:32:18
 */
public class HailstoneSequence {

	
	public static void main(String[] args) {
		String[] temp = getHailstoneLength(42).split(",");
		System.out.println("序列长度：" + temp.length);
		System.out.println(Arrays.toString(temp));
	}

	public static String getHailstoneLength(int number){
		
		StringBuilder sb = new StringBuilder(number + "");

		while (number > 1) {
			number = (number % 2 == 0) ? number / 2 : 3 * number + 1;
			sb.append("," + number);
		}
		return sb.toString();
	}
}
